View Javadoc
1 /* 2 * MainView 3 * 4 * $RCSfile: MainView.java,v $ 5 * $Revision: 1.3 $ 6 * $Date: 2004/01/04 18:51:04 $ 7 * $Source: /cvsroot/jpui/jpui/src/MainView.java,v $ 8 * 9 * JPUI - Java Preferences User Interface 10 * Copyright (C) 2003 11 * 12 * This program is free software; you can redistribute it and/or modify it 13 * under the terms of the GNU General Public License as published by the Free 14 * Software Foundation; either version 2 of the License, or (at your option) 15 * any later version. 16 * 17 * This program is distributed in the hope that it will be useful, but WITHOUT 18 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 19 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 20 * more details. 21 * 22 * You should have received a copy of the GNU General Public License along with 23 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple 24 * Place, Suite 330, Boston, MA 02111-1307 USA 25 * 26 * Author: macksold@users.sourceforge.net 27 */ 28 29 import java.awt.event.ActionEvent; 30 import java.awt.event.ActionListener; 31 import java.util.Observable; 32 import java.util.Observer; 33 34 import javax.swing.JMenu; 35 import javax.swing.JMenuBar; 36 import javax.swing.JMenuItem; 37 38 /*** 39 * View that is responsible for menu commands. 40 * Delegates menu command implementation to the relevant view. 41 */ 42 public class MainView implements Observer, ActionListener { 43 // menu bar 44 private JMenuBar moMenuBar; 45 46 // menu action commands 47 private static final String EXIT = "exit"; 48 private static final String NODE_NEW = "node_new"; 49 private static final String NODE_DELETE = "node_delete"; 50 private static final String KEY_NEW = "key_new"; 51 private static final String KEY_DELETE = "key_delete"; 52 53 // references to views which will perform the work 54 // associated with the menu items 55 private TreeView moTreeView; 56 private EditNodeView moEditNodeView; 57 58 /*** 59 * ctor 60 * @param oTreeView left side tree view 61 * @param oEditNodeView right side edit node view 62 */ 63 public MainView(TreeView oTreeView, EditNodeView oEditNodeView) { 64 moTreeView = oTreeView; 65 moEditNodeView = oEditNodeView; 66 initMenu(); 67 PreferencesModel.Instance().addObserver(this); 68 } 69 70 /*** 71 * Populate the menu 72 */ 73 protected void initMenu() { 74 moMenuBar = new JMenuBar(); 75 JMenu oMenu = new JMenu(Resources.getString("menu_file")); 76 JMenuItem oMenuItem = new JMenuItem(Resources.getString("file_exit")); 77 oMenuItem.setActionCommand(EXIT); 78 oMenuItem.addActionListener(this); 79 oMenu.add(oMenuItem); 80 81 moMenuBar.add(oMenu); 82 83 // add/delete nodes from current node 84 oMenu = new JMenu(Resources.getString("menu_node")); 85 oMenuItem = new JMenuItem(Resources.getString("node_new")); 86 oMenuItem.setActionCommand(NODE_NEW); 87 oMenuItem.addActionListener(this); 88 oMenu.add(oMenuItem); 89 oMenuItem = new JMenuItem(Resources.getString("node_delete")); 90 oMenuItem.setActionCommand(NODE_DELETE); 91 oMenuItem.addActionListener(this); 92 oMenu.add(oMenuItem); 93 moMenuBar.add(oMenu); 94 95 // add/delete keys on current node 96 oMenu = new JMenu(Resources.getString("menu_attribute")); 97 oMenuItem = new JMenuItem(Resources.getString("attribute_new")); 98 oMenuItem.setActionCommand(KEY_NEW); 99 oMenuItem.addActionListener(this); 100 oMenu.add(oMenuItem); 101 oMenuItem = new JMenuItem(Resources.getString("attribute_delete")); 102 oMenuItem.setActionCommand(KEY_DELETE); 103 oMenuItem.addActionListener(this); 104 oMenu.add(oMenuItem); 105 moMenuBar.add(oMenu); 106 } 107 108 /*** 109 * @return javax.swing.JMenuBar 110 */ 111 public JMenuBar getMenuBar() { 112 return moMenuBar; 113 } 114 115 /*** 116 * Process menu selection 117 * 118 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) 119 */ 120 public void actionPerformed(ActionEvent e) { 121 if (e.getActionCommand().equals(EXIT)) { 122 System.exit(0); 123 } 124 else if (e.getActionCommand().equals(NODE_NEW)) { 125 moTreeView.newNode(); 126 } 127 else if (e.getActionCommand().equals(NODE_DELETE)) { 128 moTreeView.deleteNode(); 129 } 130 else if (e.getActionCommand().equals(KEY_NEW)) { 131 moEditNodeView.newKey(); 132 } 133 else if (e.getActionCommand().equals(KEY_DELETE)) { 134 moEditNodeView.deleteKey(); 135 } 136 } 137 138 /*** 139 * @see java.util.Observer#update(java.util.Observable, java.lang.Object) 140 */ 141 public void update(Observable o, Object arg) { 142 143 } 144 145 }

This page was automatically generated by Maven